import fetch from 'common/src/utils/fetch';

/**
 * 删除
 */
function delete_(idList, ignoreElection) {
    if (ignoreElection) {
        return fetch({
            url: '/api/arrangementservice/manualArrange?ignoreElection=true',
            method: 'delete',
            data: idList
        });
    } else {
        return fetch({
            url: '/api/arrangementservice/manualArrange',
            method: 'delete',
            data: idList
        });
    }
}

/**
 * 修改
 */
function update(template) {
    return fetch({
        url: '/api/arrangementservice/manualArrange',
        method: 'post',
        data: template
    });
}

/**
 * 新增
 */
function add(template) {
    return fetch({
        url: '/api/arrangementservice/manualArrange',
        method: 'put',
        data: template
    });
}

/**
 * 修改发布状态
 */
function deployFlag(data) {
    return fetch({
        url: '/api/arrangementservice/manualArrange/deployFlag',
        method: 'put',
        data: data
    });
}
/**
 * 复制预排课内容
 * @param {*} data
 */
function copyPre(data) {
    return fetch({
        url: '/api/arrangementservice/manualArrange/copyPre',
        method: 'put',
        data: data
    });
}

/**
 * 排课冲突检查
 * @param {*} data
 */
function checkConflict(data) {
    return fetch({
        url: '/api/arrangementservice/manualArrange/checkConflict',
        method: 'put',
        data: data
    });
}

/**
 * 研究生排课冲突检查
 */
function checkGraduateConflict(data) {
    return fetch({
        url: '/api/arrangementservice/manualArrange/checkGraduateConflict',
        method: 'put',
        data: data
    });
}

function getReportStatus(key) {
    return fetch({
        url: '/api/arrangementservice/assistData/workload/result/' + key,
        method: 'get'
    });
}

/**
 * 查询列表
 */
function searchList(data, profile, showPre) {
    let url = '/api/arrangementservice/manualArrange/page2?1=1';
    if (profile) {
        url += '&profile';
    }
    if (showPre) {
        url += '&showpre';
    }
    return fetch({
        url,
        method: 'post',
        data: data
    });
}

/**
 * 查询列表(不进行数据分权查询)
 */
function searchListWithOutAuth(data, profile) {
    let url = '/api/arrangementservice/manualArrange/page';
    if (profile) {
        url += '?profile';
    }
    return fetch({
        url,
        method: 'post',
        data: data
    });
}

/**
 * 查询列表(不进行数据分权查询)
 */
function searchListWithOutAuthPrint(data, profile) {
    let url = '/api/arrangementservice/manualArrange/pagePrint';
    if (profile) {
        url += '?profile';
    }
    return fetch({
        url,
        method: 'post',
        data: data
    });
}



/**
 *
 * 导出辅助数据管理列表
 */
function exportAssistList(data) {
    return fetch({
        url: '/api/arrangementservice/manualArrange/export',
        method: 'post',
        data: data
    });
}

function exportTaskList(data) {
    return fetch({
        url: '/api/arrangementservice/manualArrange/exportTaskList',
        method: 'post',
        data: data
    });
}

function exportSchoolCheckList(data) {
    return fetch({
        url: '/api/arrangementservice/teachingClass/exportSchoolCheckList',
        method: 'post',
        data: data
    });
}

function getTaskReportStatus(key) {
    return fetch({
        url: '/api/arrangementservice/manualArrange/result/' + key,
        method: 'get'
    });
}

function getClassForEdit(data) {
    return fetch({
        url: '/api/arrangementservice/manualArrange/getClassForEdit',
        method: 'post',
        data: data
    });
}

/**
 * 根据ID更新教学班
 */
function updateClass(data) {
    return fetch({
        url: '/api/arrangementservice/teachingClass',
        method: 'post',
        data: data
    });
}
/**
 * 根据Id查询教学班全量信息
 */
function getClass(classId) {
    return fetch({
        url: '/api/arrangementservice/manualArrange/class/' + classId,
        method: 'get'
    });
}

/**
 * 查询冲突的时间
 */
function getOtherUseTimes(classId) {
    return fetch({
        url: '/api/arrangementservice/manualArrange/otherUseTimes/' + classId,
        method: 'get'
    });
}

function getArrangeRoom(id) {
    return fetch({
        url: '/api/arrangementservice/manualArrange/room/' + id,
        method: 'get'
    });
}

/**
 * 查询教学班详情
 */
function getDetail(classId) {
    return fetch({
        url: '/api/arrangementservice/manualArrange/getDetail?classId=' +
            classId,
        method: 'get'
    });
}

function getFaculty() {
    return fetch({
        url: 'api/userservice/dept/findDept',
        method: 'get'
    });
}

function intelligent(data) {
    return fetch({
        url: '/api/arrangementservice/manualArrange/intelligent',
        method: 'post',
        data: data
    });
}

function unarragedCourseNum(calendar, isRetraining) {
    return fetch({
        url: '/api/arrangementservice/manualArrange/unarragedCourseNum/'+ calendar + '/' + (!isRetraining ? 0 : isRetraining),
        method: 'get'
    });
}

function fullDeployFlag(data) {
    return fetch({
        url: '/api/arrangementservice/manualArrange/fullDeployFlag',
        method: 'put',
        data: data
    });
}

/**
 * 新增
 */
function swapTeacher(param) {
    return fetch({
        url: '/api/arrangementservice/manualArrange/swapTeacher',
        method: 'put',
        data: param
    });
}

function swapClassroom(param) {
    return fetch({
        url: '/api/arrangementservice/manualArrange/swapClassroom',
        method: 'put',
        data: param
    });
}

export default {
    delete_: delete_,
    update: update,
    add: add,
    searchList: searchList,
    deployFlag: deployFlag,
    copyPre: copyPre,
    checkConflict: checkConflict,
    checkGraduateConflict: checkGraduateConflict,
    getOtherUseTimes: getOtherUseTimes,
    getArrangeRoom: getArrangeRoom,
    updateClass: updateClass,
    exportAssistList: exportAssistList,
    exportSchoolCheckList: exportSchoolCheckList,
    getReportStatus: getReportStatus,
    getClassForEdit: getClassForEdit,
    getClass: getClass,
    getDetail: getDetail,
    searchListWithOutAuth: searchListWithOutAuth,
    exportTaskList: exportTaskList,
    getTaskReportStatus: getTaskReportStatus,
    getFaculty: getFaculty,
    intelligent: intelligent,
    unarragedCourseNum: unarragedCourseNum,
    fullDeployFlag: fullDeployFlag,
    searchListWithOutAuthPrint:searchListWithOutAuthPrint,
    swapTeacher: swapTeacher,
    swapClassroom: swapClassroom
};
